from ast import mod
from datetime import datetime
from email.policy import default
from enum import unique
from django.db import models
from django.contrib.auth.models import User

from scrum.models import Product

# Create your here.

# 领域
REALM = (
        (0, '其他'),
        (1, '健康医疗'),
        (2, '新能源汽车'),
        (3, '智能电网'),
        (4, '临空产业'),
        (5, '现代农业'),
        (6, '信息技术业'),
        (7, '电子、人工智能'),
        (8, '医药、生物制品'),
        (9, '新材料'),
        (10, '林、牧、渔业'),
        (11, '高端装备制造业'),
        (12, '机械、设备、仪表'),
        (13, '环保'),
        (14, '制造业'),
        (15, '金融、保险业'),
        (16, '水利'),
        (17, '石油、化学、塑料、塑胶'),
        (18, '社会服务业'),

    )

# 合作方式
CooperationMode = (
    (0, '其他'),
    (1, '项目融资'),
    (2, '技术转让'),
    (3, '技术开发'),
    (4, '股权合作'),
    (5, '产学研合作'),
    (6, '技术咨询'),
    (7, '技术服务'),
    (8, '技术许可'),
)

# 成果阶段
STAGE = (
    (0, '其他'),
    (1, '初期阶段'),
    (2, '中期阶段'),
    (3, '成熟应用阶段'),
)

# 成果水平
LEVEL = (
    (0, '未评价'),
    (1, '国队领先'),
    (2, '国际先进'),
    (3, '国内领先'),
    (4, '国内先进'),
    (5, '国内一般'),
)

# 知识产权情况 intellectual property
IntellectualProperty = (
    (0, '其他'),
    (0, '专利权'),
    (0, '软件著作权'),
    (0, '集成电路布图设计专有权'),
    (0, '商标权'),
    (0, '技术秘密'),
    (0, '植物新品种权'),
    (0, '商号权'),
)




class Expert(models.Model): # 专家

    name = models.CharField('专家姓名', max_length=50)

    realm = models.IntegerField('所属领域', default=0, choices=REALM)

    title = models.CharField('职称', max_length=50, null=True, blank=True) # 职称

    work_unit = models.CharField('工作单位', max_length=50, null=True, blank=True)

    duty = models.CharField('职务', max_length=50, null=True, blank=True)

    id_card = models.CharField('身份证号', max_length=18, null=True, blank=True, unique=True)

    phone = models.CharField('手机号', max_length=11, unique=True)

    email = models.CharField('联系邮箱',max_length=100, null=True, blank=True, unique=True)

    bank_card = models.CharField('银行卡号', max_length=50, null=True, blank=True)

    bank = models.CharField('开户行', max_length=50, null=True, blank=True)

    introduce = models.TextField('专家介绍', null=True, blank=True)


    def __str__(self) -> str:

        return f"{self.name}: {self.work_unit}-{self.duty}"

    class Meta:
        verbose_name = "专家"
        verbose_name_plural = "专家"

class Roadshow(models.Model):

    expert = models.ForeignKey(Expert, on_delete=models.PROTECT, verbose_name='专家')

    activity = models.ForeignKey(Product, on_delete=models.PROTECT, verbose_name='活动名称', null=True, blank=True)

    road_show = models.CharField('路演名称', max_length=50)

    start_date = models.DateTimeField('路演时间', default=datetime.now())

    introduce = models.TextField('路演内容简介', null=True, blank=True)

    def __str__(self) -> str:

        return f"专家：{self.expert__name}, 路演：{self.road_show}"

    class Meta:

        verbose_name = "专家路演"
        verbose_name_plural = "专家路演"


class Achievements(models.Model): # Scientific and technological achievements 科技成果

    user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='成查添加人员')

    unit = models.CharField('单位名称', max_length=50)

    unit_properties = models.CharField('单位性质', max_length=50)

    achievements = models.CharField('成果名称', max_length=300)

    holder = models.CharField('成果持有人', max_length=30)

    duty = models.CharField('职务/职称', max_length=30, null=True, blank=True)

    education = models.CharField('学历/学位', max_length=30, null=True, blank=True)

    phone = models.CharField('联系电话', max_length=30)

    realm = models.IntegerField('所属领域', default=0, choices=REALM)

    cooperation_mode = models.IntegerField('合作方式', default=0, choices=CooperationMode)

    stage = models.IntegerField('成果所处阶段', default=0, choices=STAGE)

    level = models.IntegerField('成果水平', default=0, choices=LEVEL)

    intellectual_property = models.IntegerField('知识产权情况', default=0, choices=IntellectualProperty)

    introduce = models.TextField('成果简介')

    member = models.TextField('成员简介', null=True, blank=True)

    create_date = models.DateTimeField('成果添加时间', default=datetime.now())

    def __str__(self) -> str:

        return self.achievements

    class Meta:

        verbose_name = "科技成果"
        verbose_name_plural = "科技成果"



class Demand(models.Model): # 科技需求提交表

    create_date = models.DateTimeField('需求添加时间', default=datetime.now())

    raw_json = models.JSONField('原始JSON数据', unique=True)

    def __str__(self) -> str:

        return self.raw_json.get("需求单位名称")

    class Meta:

        verbose_name = "科技需求"
        verbose_name_plural = "科技需求"